"""
flatMap算子：对 rdd 执行 map 操作，再进行 解除嵌套 操作
"""
from pyspark import SparkConf, SparkContext
import os
os.environ['PYSPARK_PYTHON'] = "C:/Users/Lenovo/AppData/Local/Programs/Python/Python310/python.exe"

conf = SparkConf().setMaster("local[*]").setAppName("test_spark")
sc = SparkContext(conf=conf)

# 准备一个RDD
rdd = sc.parallelize(["itheima itcast 666", "itheima json", "python spark"])

# 需求：将RDD数据里的元素一个个提取出来
rdd2 = rdd.flatMap(lambda x: x.split(" "))   # 注意：空格别忘记
print(rdd2.collect())